import { protectedRequest } from './index';
const request = protectedRequest();

/**
 * 获取delivery列表
 */
const deliveryListReq = () => request({
  method: 'get',
  url: `/delivery/list`,
});

/**
 * 通过id查找送货单
 * @param {number} id 
 */
const deliveryCheckReq = (id) => request({
  method: 'get',
  url: `/delivery/check/${id}`,
});

/**
 * 为clientId的客户添加一张送货单
 * @param {number} clientId 
 * @param {object} delivery
 * @param {Array} orderIds
 */
const deliveryAppendReq = (clientId, delivery, orderIds) => request({
  method: 'post',
  url: `/delivery/append/${clientId}`,
  data: {
    delivery,
    orderIds
  }
});

/**
 * 更新送货单信息
 * @param {number} id 
 * @param {object} data 
 */
const deliveryUpdateReq = (id, data) => request({
  method: 'put',
  url: `/delivery/update/${id}`,
  data
});

/**
 * 删除送货单的一张订单
 * @param {number} id 
 * @param {data} object
 */
const deliveryRemoveOrderReq = (id, data) => request({
  method: 'put',
  url: `/delivery/remove/${id}`,
  data
})

/**
 * 添加送货单的订单
 * @param {number} id 
 * @param {data} object
 */
const deliveryAddOrderReq = (id, data) => request({
  method: 'put',
  url: `/delivery/add/${id}`,
  data
})

/**
 * 根据id删除送货单
 * @param {number} id
 */
const deliveryDelReq = (id) => request({
  method: 'delete',
  url: `/delivery/delete/${id}`,
});

/**
 * 审核对应id的送货单
 * @param {number} id 
 */
const deliveryReviewReq = (id) => request({
  method: 'get',
  url: `/delivery/review/${id}`,
});

/**
 * 取消审核对应id的送货单
 * @param {number} id 
 */
const deliveryUnreviewReq = (id) => request({
  method: 'get',
  url: `/delivery/unreview/${id}`,
});

/**
 * 对应送货单已付款
 * @param {number} id 
 */
const deliveryPayReq = (id) => request({
  method: 'get',
  url: `/delivery/pay/${id}`,
});

/**
 * 对应送货单取消已付款
 * @param {number} id 
 */
const deliveryUnPayReq = (id) => request({
  method: 'get',
  url: `/delivery/unpay/${id}`,
});

export {
  deliveryListReq,
  deliveryCheckReq,
  deliveryAppendReq,
  deliveryUpdateReq,
  deliveryRemoveOrderReq,
  deliveryDelReq,
  deliveryReviewReq,
  deliveryUnreviewReq,
  deliveryPayReq,
  deliveryUnPayReq,
  deliveryAddOrderReq
}
